﻿using MapsterMapper;
using Microsoft.AspNetCore.Components;
using MXERP.Infrastructure.Managers;
using MXERP.Shared.Extensions;

namespace MXERP.Client.Pages.Systems
{
    public partial class App
    {
        [Inject]
        public IAppManager AppManager { get; set; } = default!;
        [Inject]
        public IMapper Mapper { get; set; } = default!;
        private HashSet<AppTreeResponse>? _selectedItems;
        private List<AppTreeResponse>? _apps;
        protected override async Task OnInitializedAsync()
        {
            var result = await AppManager.Query();
            var data = Mapper.Map<List<AppTreeResponse>>(result.Data);
            _apps = data.ToTree();
        }
        private async Task Remove()
        {
            if (_selectedItems == null || _selectedItems.Count <= 0)
            {
                Snackbar.Add("请选择应用!", Severity.Error);
                return;
            }
        }
        private async Task Edit()
        {
            if (_selectedItems == null || _selectedItems.Count <= 0)
            {
                Snackbar.Add("请选择应用!", Severity.Error);
                return;
            }
            if (_selectedItems.Count > 1)
            {
                Snackbar.Add("只能选择一个应用!", Severity.Error);
                return;
            }
            await DialogService.ShowAsync<AppForm>();
        }
    }
}
